package com.sw.small_world.fragment.me.myinfo;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.sw.small_world.R;
import com.sw.small_world.activity.ClickButtonActivity;
import com.sw.small_world.fragment.base.BaseFragment;
import com.sw.small_world.utils.ConstantUtils;
import com.sw.small_world.utils.DateUtils;

import java.util.ArrayList;
import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import shanyao.pickview.OptionsPickerView;
import shanyao.pickview.TimePickerView;
import shanyao.pickview.utils.PickViewUtils;

/**
 * Created by Administrator on 2017/3/16.
 */

public class AddEduExFragment extends BaseFragment {


    @Bind(R.id.et_school)
    EditText etSchool;
    @Bind(R.id.tv_edu_bg)
    TextView tvEduBg;
    @Bind(R.id.tv_start_time)
    TextView tvStartTime;
    @Bind(R.id.tv_end_time)
    TextView tvEndTime;
    private ClickButtonActivity activity;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (ClickButtonActivity) getActivity();
        setActionBar();
    }

    @Override
    protected Object requestData() {
        return ConstantUtils.STATE_SUCCESSED;
    }

    @Override
    protected View getSuccessView() {
        View view = View.inflate(activity, R.layout.fragment_add_edu_ex, null);
        ButterKnife.bind(this, view);
        return view;
    }

    private void setActionBar() {
        activity.tvTitle.setText("教育经历");
        activity.tvRight.setVisibility(View.VISIBLE);
        activity.tvRight.setText("保存");
        activity.tvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.tv_edu_bg, R.id.tv_start_time, R.id.tv_end_time})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_edu_bg:
                final ArrayList<String> eduBgList = new ArrayList<>();
                eduBgList.add("专科");
                eduBgList.add("本科");
                eduBgList.add("硕士");
                eduBgList.add("博士");
                eduBgList.add("其他");
                PickViewUtils.initOptionPickView(activity, eduBgList, "请选择学历", new OptionsPickerView.OnOptionsSelectListener() {
                    @Override
                    public void onOptionsSelect(int options1, int option2, int options3) {
                        tvEduBg.setText(eduBgList.get(options1));
                    }
                }).show();
                break;
            case R.id.tv_start_time:
                PickViewUtils.initTimePickView(activity, TimePickerView.Type.YEAR_MONTH, new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date) {
                        tvStartTime.setText(DateUtils.getTime(date));
                    }
                }).show();
                break;
            case R.id.tv_end_time:
                PickViewUtils.initTimePickView(activity, TimePickerView.Type.YEAR_MONTH, new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date) {
                        tvEndTime.setText(DateUtils.getTime(date));
                    }
                }).show();
                break;
        }
    }
}
